<script setup>
import {ref} from "vue";

const tableData = [
  {
    date: '2016-05-03',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-02',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-04',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-01',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
]
const arr = ref([
  {name: '张三', salary: 10000, job: '维修员'},
  {name: '李四', salary: 20000, job: '保安'},
  {name: '王五', salary: 30000, job: '经理'},
  {name: '赵六', salary: 40000, job: '总监'},
])
const del = (index, emp) => {
  if (confirm('确定删除' + emp.name + '吗？')) {
    arr.value.splice(index, 1)
  }
}
</script>

<template>
  <h1>表格组件</h1>
  <el-table :data="tableData" style="width: 50%">
    <el-table-column prop="date" label="日期" width="180"/>
    <el-table-column prop="name" label="姓名" width="180"/>
    <el-table-column prop="address" label="住址"/>
  </el-table>
  <hr>
  <el-table :data="arr" style="width: 50%;margin: 0 auto;">

    <el-table-column type="index" label="编号" width="80" align="center"/>
    <el-table-column prop="name" label="姓名" align="center"/>
    <el-table-column prop="salary" label="工资" align="center"/>
    <el-table-column prop="job" label="职位" align="center"/>
    <el-table-column label="操作">
      <!-- 自定义列模版tempLate -->
      <!-- #default定义了一个插槽(sLot)名为default
            scope就是插槽上的一个对象, 该对象是一个范围对象,可保存上下文数据-->
      <template #default="scope">
        <!-- scope对象保存了当前行数据的索引$index(从日开始)与当前行完整的对象scope. row -->
        <el-button type="danger" @click="del(scope.$index,scope.row)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>

</template>

<style scoped>

</style>













